package com.viettel.core.dao.report;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.Type;

import com.viettel.core.entities.report.vo.ReportDetailFilter;
import com.viettel.core.entities.report.vo.ReportDetailVO;
import com.viettel.core.enumtype.ReportGeneralType;
import com.viettel.core.exceptions.DataAccessException;
import com.viettel.core.repo.IRepository;

public class ReportDetailDAOImpl implements ReportDetailDAO{

	private IRepository repo;

	public void setRepo(IRepository repo) {
		this.repo = repo;
	}

	@Override
	public List<ReportDetailVO> getReportDetailText(ReportDetailFilter filter)
			throws DataAccessException {
		List<Object> selectParams = new ArrayList<Object>();
		StringBuilder selectSql = new StringBuilder();
		StringBuilder countSql = new StringBuilder();
		StringBuilder fromQuery = new StringBuilder();

		selectSql.append("SELECT service_number serviceNumber, \n");
		selectSql.append("  group_name groupName, \n");
		selectSql.append("  service_code serviceCode, \n");
		selectSql.append("  SUM(sms_receive) smsReceive, \n");
		selectSql.append("  SUM(sms_sent) smsSent, \n");
		selectSql.append("  SUM(sms_valid) smsValid, \n");
		selectSql.append("  SUM(sms_repair) smsRepair, \n");
		selectSql.append("  SUM(sms_error) smsError, \n");
		selectSql.append("  SUM(money) money, \n");
		selectSql.append("  SUM(money_vat) moneyVAT \n");
		if(filter.getTypeReport().equals(ReportGeneralType.TODAY)){
			fromQuery.append("FROM report_text_daily \n");
			fromQuery.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YESTERDAY)){
			fromQuery.append("FROM report_text_daily \n");
			fromQuery.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate-1,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_MONTH)){
			fromQuery.append("FROM report_text_monthly \n");
			fromQuery.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(sysdate,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.LAST_MONTH)){
			fromQuery.append("FROM report_text_monthly \n");
			fromQuery.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(trunc(sysdate,'MM')-1,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_YEAR)){
			fromQuery.append("FROM report_text_monthly \n");
			fromQuery.append("WHERE round(REPORT_MONTH/100)=TO_NUMBER(TO_CHAR(sysdate,'yyyy')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.DATE_RANGE)){
			fromQuery.append("FROM report_text_daily \n");
			fromQuery.append("WHERE TRUNC(report_date,'DD') >= TO_DATE(?,'dd/MM/yyyy') \n");
			fromQuery.append("AND TRUNC(report_date,'DD')   <= TO_DATE(?,'dd/MM/yyyy') \n");
			selectParams.add(filter.getFromDate());
			selectParams.add(filter.getToDate());
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.MONTH_RANGE)){
			String[] monthFrom = filter.getFromDate().split("/");
            Long monthFr = Long.valueOf(monthFrom[1] + monthFrom[0]);
            String[] monthTo =filter.getToDate().split("/");
            Long monthToL = Long.valueOf(monthTo[1] + monthTo[0]);
			
			fromQuery.append("FROM report_text_monthly \n");
			fromQuery.append("WHERE REPORT_MONTH >=? and  REPORT_MONTH <=? \n");
			selectParams.add(monthFr);
			selectParams.add(monthToL);
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YEAR_RANGE)){
			fromQuery.append("FROM report_text_monthly \n");
			fromQuery.append("WHERE round(REPORT_MONTH/100) >= ? and  round(REPORT_MONTH/100) <= ? \n");
			selectParams.add(filter.getFromDate().split("/")[0]);
			selectParams.add(filter.getToDate().split("/")[0]);
		}
		
		if (filter.getGroupId() != null && !filter.getGroupId().equals(0)) {
			fromQuery.append("AND group_id         =? \n");
			selectParams.add(filter.getGroupId());
		}
		if (filter.getTelco() != null) {
			fromQuery.append("AND telco            =? \n");
			selectParams.add(filter.getTelco());
		}
		if (filter.getServiceNumber() != null) {
			fromQuery.append("AND service_number   =? \n");
			selectParams.add(filter.getServiceNumber());
		}
		
		if (filter.getServiceId() != null) {
			fromQuery.append("AND service_id   =? \n");
			selectParams.add(filter.getServiceId());
		}
		
		if (filter.getServiceCode() != null) {
			fromQuery.append("AND ( lower(service_code) LIKE (?) ESCAPE '/' \n");
			fromQuery.append("OR lower(service_name) LIKE (?) ESCAPE '/' ) \n");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() +"%");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() + "%");
		}

		selectSql.append(fromQuery);
		selectSql.append("GROUP BY service_number, \n");
		selectSql.append("  group_name, service_code \n");
		selectSql.append("ORDER BY serviceNumber, \n");
		selectSql.append("  lower(groupName), lower(serviceCode) ");

		countSql.append("SELECT COUNT(*) AS COUNT ").append("from (select 1 ")
				.append(fromQuery)
				.append(" GROUP BY service_number, group_name) ");

		String[] fieldNames = new String[] { 
				"serviceNumber", "groupName", "smsReceive",
				"smsSent","smsValid","smsRepair",
				"smsError","money","moneyVAT",
				"serviceCode"
				};

		Type[] fieldTypes = new Type[] { 
				StandardBasicTypes.STRING, StandardBasicTypes.STRING, StandardBasicTypes.LONG,
				StandardBasicTypes.LONG, StandardBasicTypes.LONG, StandardBasicTypes.LONG,
				StandardBasicTypes.LONG, StandardBasicTypes.LONG, StandardBasicTypes.LONG,
				StandardBasicTypes.STRING
		};

		List<ReportDetailVO> list = null;
		if (filter.getPaging() == null) {
			list = repo.getListByQueryAndScalar(ReportDetailVO.class, fieldNames,
					fieldTypes, selectSql.toString(), selectParams);
		} else {
			list = repo.getListByQueryAndScalarPaginated(ReportDetailVO.class,
					fieldNames, fieldTypes, selectSql.toString(),
					countSql.toString(), selectParams, selectParams,
					filter.getPaging());
		}
		return list;
	}

	@Override
	public List<ReportDetailVO> getReportDetailSub(ReportDetailFilter filter)
			throws DataAccessException {
		List<Object> selectParams = new ArrayList<Object>();
		StringBuilder selectSql = new StringBuilder();
		StringBuilder countSql = new StringBuilder();
		StringBuilder fromQuery = new StringBuilder();

		selectSql.append("SELECT group_name groupName, \n");
		selectSql.append("  service_code serviceCode, \n");
		selectSql.append("  service_number serviceNumber, \n");
		selectSql.append("  SUM(total_subscription) totalSubscription, \n");
		selectSql.append("  SUM(charge_total) chargeTotal, \n");
		selectSql.append("  SUM(charge_ok) chargeOk, \n");
		selectSql.append("  SUM(charge_nok_1) chargeNOK1, \n");
		selectSql.append("  SUM(charge_nok_2) chargeNOK2, \n");
		selectSql.append("  SUM(charge_nok_3) chargeNOK3, \n");
		selectSql.append("  SUM(sub_sent) smsSent, \n");
		selectSql.append("  SUM(money) money, \n");
		selectSql.append("  SUM(money_vat) moneyVAT \n");
		if(filter.getTypeReport().equals(ReportGeneralType.TODAY)){
			fromQuery.append("FROM report_sub_daily \n");
			fromQuery.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YESTERDAY)){
			fromQuery.append("FROM report_sub_daily \n");
			fromQuery.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate-1,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_MONTH)){
			fromQuery.append("FROM report_sub_monthly \n");
			fromQuery.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(sysdate,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.LAST_MONTH)){
			fromQuery.append("FROM report_sub_monthly \n");
			fromQuery.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(trunc(sysdate,'MM')-1,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_YEAR)){
			fromQuery.append("FROM report_sub_monthly \n");
			fromQuery.append("WHERE round(REPORT_MONTH/100)=TO_NUMBER(TO_CHAR(sysdate,'yyyy')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.DATE_RANGE)){
			fromQuery.append("FROM report_sub_daily \n");
			fromQuery.append("WHERE TRUNC(report_date,'DD') >= TO_DATE(?,'dd/MM/yyyy') \n");
			fromQuery.append("AND TRUNC(report_date,'DD')   <= TO_DATE(?,'dd/MM/yyyy') \n");
			selectParams.add(filter.getFromDate());
			selectParams.add(filter.getToDate());
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.MONTH_RANGE)){
			String[] monthFrom = filter.getFromDate().split("/");
            Long monthFr = Long.valueOf(monthFrom[1] + monthFrom[0]);
            String[] monthTo =filter.getToDate().split("/");
            Long monthToL = Long.valueOf(monthTo[1] + monthTo[0]);
			
			fromQuery.append("FROM report_sub_monthly \n");
			fromQuery.append("WHERE REPORT_MONTH >=? and  REPORT_MONTH <=? \n");
			selectParams.add(monthFr);
			selectParams.add(monthToL);
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YEAR_RANGE)){
			fromQuery.append("FROM report_sub_monthly \n");
			fromQuery.append("WHERE round(REPORT_MONTH/100) >= ? and  round(REPORT_MONTH/100) <= ? \n");
			selectParams.add(filter.getFromDate().split("/")[0]);
			selectParams.add(filter.getToDate().split("/")[0]);
		}
		
		if (filter.getGroupId() != null && !filter.getGroupId().equals(0)) {
			fromQuery.append("AND group_id         =? \n");
			selectParams.add(filter.getGroupId());
		}
		if (filter.getTelco() != null) {
			fromQuery.append("AND telco            =? \n");
			selectParams.add(filter.getTelco());
		}
		if (filter.getServiceNumber() != null) {
			fromQuery.append("AND service_number   =? \n");
			selectParams.add(filter.getServiceNumber());
		}
		
		if (filter.getServiceId() != null) {
			fromQuery.append("AND service_id   =? \n");
			selectParams.add(filter.getServiceId());
		}
		
		if (filter.getServiceCode() != null) {
			fromQuery.append("AND ( lower(service_code) LIKE (?) ESCAPE '/' \n");
			fromQuery.append("OR lower(service_name) LIKE (?) ESCAPE '/' ) \n");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() +"%");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() + "%");
		}

		selectSql.append(fromQuery);
		selectSql.append("GROUP BY group_name, service_code, service_number  \n");
		selectSql.append("ORDER BY lower(groupName), lower(serviceCode), lower(serviceNumber) \n");

		countSql.append("SELECT COUNT(*) AS COUNT ").append("from (select 1 ")
				.append(fromQuery)
				.append(" GROUP BY group_name, service_code, service_number) ");

		String[] fieldNames = new String[] { 
				"groupName", "serviceCode","serviceNumber",
				"totalSubscription", "chargeTotal", "chargeOk",
				"chargeNOK1","chargeNOK2", "chargeNOK3",
				"smsSent","money", "moneyVAT"
				};

		Type[] fieldTypes = new Type[] { 
				StandardBasicTypes.STRING, StandardBasicTypes.STRING, StandardBasicTypes.STRING,
				StandardBasicTypes.LONG, StandardBasicTypes.LONG, StandardBasicTypes.LONG, 
				StandardBasicTypes.LONG, StandardBasicTypes.LONG, StandardBasicTypes.LONG, 
				StandardBasicTypes.LONG, StandardBasicTypes.LONG, StandardBasicTypes.LONG
		};

		List<ReportDetailVO> list = null;
		if (filter.getPaging() == null) {
			list = repo.getListByQueryAndScalar(ReportDetailVO.class, fieldNames,
					fieldTypes, selectSql.toString(), selectParams);
		} else {
			list = repo.getListByQueryAndScalarPaginated(ReportDetailVO.class,
					fieldNames, fieldTypes, selectSql.toString(),
					countSql.toString(), selectParams, selectParams,
					filter.getPaging());
		}
		return list;
	}

	@Override
	public List<ReportDetailVO> getReportDetailAll(ReportDetailFilter filter)
			throws DataAccessException {
		List<Object> selectParams = new ArrayList<Object>();
		StringBuilder selectSql = new StringBuilder();
		StringBuilder countSql = new StringBuilder();
		
		selectSql.append("SELECT groupName, \n");
		selectSql.append("  serviceCode, \n");
		selectSql.append("  serviceNumber, \n");
		selectSql.append("  SUM(totalSubscription) totalSubscription, \n");
		selectSql.append("  SUM(chargeOk) chargeOk, \n");
		selectSql.append("  SUM(chargeNOK1) chargeNOK1, \n");
		selectSql.append("  SUM(chargeNOK2) chargeNOK2, \n");
		selectSql.append("  SUM(chargeNOK3) chargeNOK3, \n");
		selectSql.append("  SUM(smsSent) smsSent, \n");
		selectSql.append("  SUM(money) money, \n");
		selectSql.append("  SUM(moneyVAT) moneyVAT \n");
		selectSql.append("FROM( \n");
		selectSql.append("SELECT group_name groupName, \n");
		selectSql.append("  service_code serviceCode, \n");
		selectSql.append("  service_number serviceNumber, \n");
		selectSql.append("  sms_receive totalSubscription, \n");
		selectSql.append("  sms_sent chargeOk, \n");
		selectSql.append("  0 chargeNOK1, \n");
		selectSql.append("  0 chargeNOK2, \n");
		selectSql.append("  0 chargeNOK3, \n");
		selectSql.append("  0 smsSent, \n");
		selectSql.append("  money money, \n");
		selectSql.append("  money_vat moneyVAT \n");
		
		if(filter.getTypeReport().equals(ReportGeneralType.TODAY)){
			selectSql.append("FROM report_text_daily \n");
			selectSql.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YESTERDAY)){
			selectSql.append("FROM report_text_daily \n");
			selectSql.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate-1,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_MONTH)){
			selectSql.append("FROM report_text_monthly \n");
			selectSql.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(sysdate,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.LAST_MONTH)){
			selectSql.append("FROM report_text_monthly \n");
			selectSql.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(trunc(sysdate,'MM')-1,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_YEAR)){
			selectSql.append("FROM report_text_monthly \n");
			selectSql.append("WHERE round(REPORT_MONTH/100)=TO_NUMBER(TO_CHAR(sysdate,'yyyy')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.DATE_RANGE)){
			selectSql.append("FROM report_text_daily \n");
			selectSql.append("WHERE TRUNC(report_date,'DD') >= TO_DATE(?,'dd/MM/yyyy') \n");
			selectSql.append("AND TRUNC(report_date,'DD')   <= TO_DATE(?,'dd/MM/yyyy') \n");
			selectParams.add(filter.getFromDate());
			selectParams.add(filter.getToDate());
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.MONTH_RANGE)){
			String[] monthFrom = filter.getFromDate().split("/");
            Long monthFr = Long.valueOf(monthFrom[1] + monthFrom[0]);
            String[] monthTo =filter.getToDate().split("/");
            Long monthToL = Long.valueOf(monthTo[1] + monthTo[0]);
			
            selectSql.append("FROM report_text_monthly \n");
            selectSql.append("WHERE REPORT_MONTH >=? and  REPORT_MONTH <=? \n");
			selectParams.add(monthFr);
			selectParams.add(monthToL);
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YEAR_RANGE)){
			selectSql.append("FROM report_text_monthly \n");
			selectSql.append("WHERE round(REPORT_MONTH/100) >= ? and  round(REPORT_MONTH/100) <= ? \n");
			selectParams.add(filter.getFromDate().split("/")[0]);
			selectParams.add(filter.getToDate().split("/")[0]);
		}
		
		if (filter.getGroupId() != null && !filter.getGroupId().equals(0)) {
			selectSql.append("AND group_id         =? \n");
			selectParams.add(filter.getGroupId());
		}
		if (filter.getTelco() != null) {
			selectSql.append("AND telco            =? \n");
			selectParams.add(filter.getTelco());
		}
		if (filter.getServiceNumber() != null) {
			selectSql.append("AND service_number   =? \n");
			selectParams.add(filter.getServiceNumber());
		}
		
		if (filter.getServiceId() != null) {
			selectSql.append("AND service_id   =? \n");
			selectParams.add(filter.getServiceId());
		}
		
		if (filter.getServiceCode() != null) {
			selectSql.append("AND ( lower(service_code) LIKE (?) ESCAPE '/' \n");
			selectSql.append("OR lower(service_name) LIKE (?) ESCAPE '/' ) \n");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() +"%");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() + "%");
		}

		selectSql.append("UNION ALL \n");
		
		selectSql.append("SELECT group_name groupName, \n");
		selectSql.append("  service_code serviceCode, \n");
		selectSql.append("  service_number serviceNumber, \n");
		selectSql.append("  total_subscription totalSubscription, \n");
		selectSql.append("  charge_ok chargeOk, \n");
		selectSql.append("  charge_nok_1 chargeNOK1, \n");
		selectSql.append("  charge_nok_2 chargeNOK2, \n");
		selectSql.append("  charge_nok_3 chargeNOK3, \n");
		selectSql.append("  sub_sent smsSent, \n");
		selectSql.append("  money money, \n");
		selectSql.append("  money_vat moneyVAT \n");
		if(filter.getTypeReport().equals(ReportGeneralType.TODAY)){
			selectSql.append("FROM report_sub_daily \n");
			selectSql.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YESTERDAY)){
			selectSql.append("FROM report_sub_daily \n");
			selectSql.append("WHERE TRUNC(report_date,'DD') = trunc(sysdate-1,'DD') \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_MONTH)){
			selectSql.append("FROM report_sub_monthly \n");
			selectSql.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(sysdate,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.LAST_MONTH)){
			selectSql.append("FROM report_sub_monthly \n");
			selectSql.append("WHERE REPORT_MONTH = TO_NUMBER(TO_CHAR(trunc(sysdate,'MM')-1,'yyyyMM')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.THIS_YEAR)){
			selectSql.append("FROM report_sub_monthly \n");
			selectSql.append("WHERE round(REPORT_MONTH/100)=TO_NUMBER(TO_CHAR(sysdate,'yyyy')) \n");
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.DATE_RANGE)){
			selectSql.append("FROM report_sub_daily \n");
			selectSql.append("WHERE TRUNC(report_date,'DD') >= TO_DATE(?,'dd/MM/yyyy') \n");
			selectSql.append("AND TRUNC(report_date,'DD')   <= TO_DATE(?,'dd/MM/yyyy') \n");
			selectParams.add(filter.getFromDate());
			selectParams.add(filter.getToDate());
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.MONTH_RANGE)){
			String[] monthFrom = filter.getFromDate().split("/");
            Long monthFr = Long.valueOf(monthFrom[1] + monthFrom[0]);
            String[] monthTo =filter.getToDate().split("/");
            Long monthToL = Long.valueOf(monthTo[1] + monthTo[0]);
			
            selectSql.append("FROM report_sub_monthly \n");
            selectSql.append("WHERE REPORT_MONTH >=? and  REPORT_MONTH <=? \n");
			selectParams.add(monthFr);
			selectParams.add(monthToL);
		}
		else if(filter.getTypeReport().equals(ReportGeneralType.YEAR_RANGE)){
			selectSql.append("FROM report_sub_monthly \n");
			selectSql.append("WHERE round(REPORT_MONTH/100) >= ? and  round(REPORT_MONTH/100) <= ? \n");
			selectParams.add(filter.getFromDate().split("/")[0]);
			selectParams.add(filter.getToDate().split("/")[0]);
		}
		
		if (filter.getGroupId() != null && !filter.getGroupId().equals(0)) {
			selectSql.append("AND group_id         =? \n");
			selectParams.add(filter.getGroupId());
		}
		if (filter.getTelco() != null) {
			selectSql.append("AND telco            =? \n");
			selectParams.add(filter.getTelco());
		}
		if (filter.getServiceNumber() != null) {
			selectSql.append("AND service_number   =? \n");
			selectParams.add(filter.getServiceNumber());
		}
		if (filter.getServiceId() != null) {
			selectSql.append("AND service_id   =? \n");
			selectParams.add(filter.getServiceId());
		}
		
		if (filter.getServiceCode() != null) {
			selectSql.append("AND ( lower(service_code) LIKE (?) ESCAPE '/' \n");
			selectSql.append("OR lower(service_name) LIKE (?) ESCAPE '/' ) \n");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() +"%");
			selectParams.add("%"+ filter.getServiceCode().trim().toLowerCase() + "%");
		}
		
        selectSql.append(") \n");
        selectSql.append("GROUP BY groupName, serviceCode, serviceNumber  \n");
		selectSql.append("ORDER BY lower(groupName), lower(serviceCode), lower(serviceNumber)  \n");

		countSql.append("SELECT COUNT(*) AS COUNT FROM( ").append(selectSql).append(")");

		String[] fieldNames = new String[] { 
				"groupName", "serviceCode","serviceNumber",
				"totalSubscription", "chargeOk", "chargeNOK1",
				"chargeNOK2", "chargeNOK3", "smsSent",
				"money", "moneyVAT"
				};

		Type[] fieldTypes = new Type[] { 
				StandardBasicTypes.STRING, StandardBasicTypes.STRING, StandardBasicTypes.STRING,
				StandardBasicTypes.LONG, StandardBasicTypes.LONG, StandardBasicTypes.LONG, 
				StandardBasicTypes.LONG, StandardBasicTypes.LONG, StandardBasicTypes.LONG, 
				StandardBasicTypes.LONG, StandardBasicTypes.LONG
		};

		List<ReportDetailVO> list = null;
		if (filter.getPaging() == null) {
			list = repo.getListByQueryAndScalar(ReportDetailVO.class, fieldNames,
					fieldTypes, selectSql.toString(), selectParams);
		} else {
			list = repo.getListByQueryAndScalarPaginated(ReportDetailVO.class,
					fieldNames, fieldTypes, selectSql.toString(),
					countSql.toString(), selectParams, selectParams,
					filter.getPaging());
		}
		return list;
	}
	
	
}
